package com.binance.assetservice.web.controller;

import com.binance.assetservice.api.IAssetApi;
import com.binance.assetservice.vo.request.GetAssetByCodeRequest;
import com.binance.assetservice.vo.request.asset.UserAssetDividendRequest;
import com.binance.assetservice.vo.response.PagingResult;
import com.binance.assetservice.vo.response.asset.AssetResponse;
import com.binance.assetservice.vo.response.asset.GetAssetPicResponse;
import com.binance.assetservice.vo.response.asset.SymbolResponse;
import com.binance.assetservice.vo.response.asset.UserAssetDividendResponse;
import com.binance.assetservice.web.service.IAssetService;
import com.binance.master.models.APIRequest;
import com.binance.master.models.APIRequest.VoidBody;
import com.binance.master.models.APIResponse;
import org.javasimon.aop.Monitored;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@Monitored
public class AssetController implements IAssetApi {

    @Autowired
    private IAssetService assetService;

    @Override
    public APIResponse<AssetResponse> getAssetByCode(@RequestBody @Validated APIRequest<GetAssetByCodeRequest> request)
            throws Exception {
        return APIResponse.getOKJsonResult(assetService.getAssetByCode(request.getBody()));
    }

    @Override
    public APIResponse<List<SymbolResponse>> getSymbolByAsset(@RequestBody  @Validated APIRequest<String> request) throws Exception {
        return APIResponse.getOKJsonResult(assetService.getSymbolByAsset(request.getBody()));
    }

    @Override
    public APIResponse<PagingResult<UserAssetDividendResponse>> userAssetDividend(
            @RequestBody @Validated APIRequest<UserAssetDividendRequest> request) throws Exception {
        return APIResponse.getOKJsonResult(this.assetService.userAssetDividend(request.getBody()));
    }

    @Override
    public APIResponse<List<AssetResponse>> getAllAsset(@RequestBody @Validated APIRequest<VoidBody> request)
            throws Exception {
        return APIResponse.getOKJsonResult(this.assetService.getAllAsset());
    }

    @Override
    public APIResponse<List<GetAssetPicResponse>> getAssetPic(@RequestBody @Validated APIRequest<VoidBody> request)
            throws Exception {
        return APIResponse.getOKJsonResult(this.assetService.getAssetPic());
    }

}
